package com.cs.controller;

import com.cs.pojo.Behospital;
import com.cs.pojo.People;
import com.cs.resultVO.ResultVO;
import com.cs.service.BeHospitalService;
import com.cs.service.PeopleService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping ("/behospital")
@ResponseBody
public class BeHospitalController {

    @Resource
    private BeHospitalService beHospitalService;
    @Resource
    private PeopleService peopleService;
    
    /**
     * 发药列表
     * @param pageNum 目前分页
     * @param peopleId 约束查询信息
     */
    @RequestMapping(value = "list" , method = RequestMethod.GET)
    public ResultVO<Behospital> queryBySendDrugPage(Integer pageNum , Integer peopleId){
        peopleId = peopleId==null? 0 : peopleId;
        pageNum = pageNum==null? 1 : pageNum;
        if (pageNum<0 || pageNum>100){
            pageNum = 1;
        }
        PageInfo<Behospital> behospitalPageInfo = beHospitalService.queryByPage(pageNum , 3 , peopleId);
        return new ResultVO<>(behospitalPageInfo);
    }
    
    /**
     * 主键查询
     * @param behid
     * @return
     */
    @RequestMapping(value = "{behId}" , method = RequestMethod.GET)
    public ResultVO<Behospital> queryById(@PathVariable("behId") int behid){
        Behospital behospital = beHospitalService.queryById(behid);
        People people = peopleService.queryById(behid);
        behospital.setBehName(people.getBehName());
        return new ResultVO<>(behospital);
    }
    
}
